Imports System.Data.SqlClient

Public Class cls_config_error_

    Implements ICloneable

#Region "Variables ..."
    Private str_codigo As String = "000000"
    Private str_titulo As String = ""
    Private str_descripcion As String = ""
    Private int_img As xtf_ErrManagerAlerta.errManagerImg = xtf_ErrManagerAlerta.errManagerImg.img_Nula
    Private str_botones As String = ""

    Private col_Items As Collections.Generic.List(Of cls_config_error_) = Nothing
#End Region

    Public Overrides Function ToString() As String
        Return codigo
    End Function

#Region "Propiedades ..."
    ReadOnly Property This
        Get
            Return Me
        End Get
    End Property
    ReadOnly Property ThisDescripcion As String
        Get
            Return Me.ToString
        End Get
    End Property
    ReadOnly Property pKey
        Get
            Return codigo
        End Get
    End Property
    Property codigo() As String
        Get
            codigo = str_codigo
        End Get
        Set(ByVal value As String)
            str_codigo = value
        End Set
    End Property
    Property titulo() As String
        Get
            titulo = str_titulo
        End Get
        Set(ByVal value As String)
            str_titulo = value
        End Set
    End Property
    Property descripcion() As String
        Get
            descripcion = str_descripcion
        End Get
        Set(ByVal value As String)
            str_descripcion = value
        End Set
    End Property
    Property img() As xtf_ErrManagerAlerta.errManagerImg
        Get
            img = int_img
        End Get
        Set(ByVal value As xtf_ErrManagerAlerta.errManagerImg)
            int_img = value
        End Set
    End Property
    Property botones() As String
        Get
            botones = str_botones
        End Get
        Set(ByVal value As String)
            str_botones = value
        End Set
    End Property

    Property Items() As Collections.Generic.List(Of cls_config_error_)
        Get
            Items = col_Items
        End Get
        Set(ByVal value As Collections.Generic.List(Of cls_config_error_))
            col_Items = value
        End Set
    End Property
#End Region

    Private Sub CargarColeccion(ByVal obj_Reader As SqlDataReader)
        col_Items = New Collections.Generic.List(Of cls_config_error_)
        While obj_Reader.Read()
            Dim Elemento As New cls_config_error_
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("codigo"))) = False Then
                Elemento.str_codigo = (obj_Reader.GetValue(obj_Reader.GetOrdinal("codigo")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("titulo"))) = False Then
                Elemento.str_titulo = (obj_Reader.GetValue(obj_Reader.GetOrdinal("titulo")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("descripcion"))) = False Then
                Elemento.str_descripcion = (obj_Reader.GetValue(obj_Reader.GetOrdinal("descripcion")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("img"))) = False Then
                Elemento.int_img = (obj_Reader.GetValue(obj_Reader.GetOrdinal("img")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("botones"))) = False Then
                Elemento.str_botones = (obj_Reader.GetValue(obj_Reader.GetOrdinal("botones")))
            End If
            col_Items.Add(Elemento)
        End While
    End Sub

    Private Sub CargarVariables(ByVal obj_Reader As SqlDataReader)
        obj_Reader.Read()
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("codigo"))) = False Then
            str_codigo = (obj_Reader.GetValue(obj_Reader.GetOrdinal("codigo")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("titulo"))) = False Then
            str_titulo = (obj_Reader.GetValue(obj_Reader.GetOrdinal("titulo")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("descripcion"))) = False Then
            str_descripcion = (obj_Reader.GetValue(obj_Reader.GetOrdinal("descripcion")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("img"))) = False Then
            int_img = (obj_Reader.GetValue(obj_Reader.GetOrdinal("img")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("botones"))) = False Then
            str_botones = (obj_Reader.GetValue(obj_Reader.GetOrdinal("botones")))
        End If
    End Sub

    Public Sub Modificar()
        Dim obj_Conexion As New cls_Conexion
        Try
            obj_Conexion.Conectar()
            With obj_Conexion.obj_SqlCommand
                .CommandType = CommandType.StoredProcedure
                .Connection = obj_Conexion.obj_SqlConnection
                .CommandText = "config_error__Modificar"
                .Parameters.Add("@codigo", SqlDbType.NVarChar).Value = str_codigo
                .Parameters.Add("@titulo", SqlDbType.NVarChar).Value = str_titulo
                .Parameters.Add("@descripcion", SqlDbType.NVarChar).Value = str_descripcion
                .Parameters.Add("@img", SqlDbType.Int).Value = int_img
                .Parameters.Add("@botones", SqlDbType.NVarChar).Value = str_botones
                .ExecuteNonQuery()
            End With
        Catch ex As SqlClient.SqlException
            Throw New Exception("Error al Modificar el registro de config_error_." & Chr(13) & _
           "Por favor informe del siguiente detalle técnico:" & Chr(13) & _
           "Nro de error: " & ex.ErrorCode & "." & Chr(13) & _
           "Descripción: " & ex.Message)
        Finally
            obj_Conexion.Desconectar()
            obj_Conexion = Nothing
        End Try
    End Sub

    Public Function Buscar(ByVal str_codigo As String) As Boolean
        Dim obj_Conexion As New cls_Conexion
        Dim obj_Reader As SqlDataReader
        Try
            Buscar = False
            obj_Conexion.Conectar()
            With obj_Conexion.obj_SqlCommand
                .CommandType = CommandType.StoredProcedure
                .Connection = obj_Conexion.obj_SqlConnection
                .Parameters.Add("@codigo", SqlDbType.NVarChar).Value = str_codigo
                .CommandText = "config_error__Buscar"
            End With
            obj_Reader = obj_Conexion.obj_SqlCommand.ExecuteReader
            If obj_Reader.HasRows Then
                CargarVariables(obj_Reader)
                Buscar = True
            End If
        Catch ex As SqlClient.SqlException
            Throw New Exception("Error al Buscar el registro de config_error_." & Chr(13) & _
           "Por favor informe del siguiente detalle técnico:" & Chr(13) & _
           "Nro de error: " & ex.ErrorCode & "." & Chr(13) & _
           "Descripción: " & ex.Message)
        Finally
            obj_Conexion.Desconectar()
            obj_Conexion = Nothing
            obj_Reader = Nothing
        End Try
    End Function

    Public Function CargarTodos() As Boolean
        Dim obj_Conexion As New cls_Conexion
        Dim obj_Reader As SqlDataReader
        Try
            CargarTodos = False
            obj_Conexion.Conectar()
            With obj_Conexion.obj_SqlCommand
                .CommandType = CommandType.StoredProcedure
                .Connection = obj_Conexion.obj_SqlConnection
                .CommandText = "config_error__CargarTodos"
            End With
            obj_Reader = obj_Conexion.obj_SqlCommand.ExecuteReader
            If obj_Reader.HasRows Then
                CargarColeccion(obj_Reader)
                CargarTodos = True
            End If
        Catch ex As SqlClient.SqlException
            Throw New Exception("Error al CargarTodos los registros de config_error_." & Chr(13) & _
           "Por favor informe del siguiente detalle técnico:" & Chr(13) & _
           "Nro de error: " & ex.ErrorCode & "." & Chr(13) & _
           "Descripción: " & ex.Message)
        Finally
            obj_Conexion.Desconectar()
            obj_Conexion = Nothing
            obj_Reader = Nothing
        End Try
    End Function

    Public Function Clone() As Object Implements System.ICloneable.Clone
        Dim obj_config_error_Clon As New cls_config_error_
        obj_config_error_Clon.str_codigo = Me.str_codigo
        obj_config_error_Clon.str_titulo = Me.str_titulo
        obj_config_error_Clon.str_descripcion = Me.str_descripcion
        obj_config_error_Clon.int_img = Me.int_img
        obj_config_error_Clon.str_botones = Me.str_botones
        obj_config_error_Clon.col_Items = Me.col_Items
        Return obj_config_error_Clon
    End Function

End Class
